]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
appFavorites: Only emit :changed signal on changes
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Thu, 16 Apr 2026 02:33:45 +0000 (04:33 +0200)
committerMarge Bot <marge-bot@gnome.org>
Fri, 17 Apr 2026 14:40:53 +0000 (14:40 +0000)
We were emitting the :changed signal on every setting or app-filter
change even though the actual favorites list might not have changed.

So now every time it's relevant, check if something is changed before
emitting the :changed signal.

We do a deep check of the app IDs as potentially an app could have
been removed while another is being installed during the same update
window, and the length of the IDs list wouldn't change.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4180>

js/ui/appFavorites.js

index b4dec3aaca4f6c74e43f1de7c99882abd21e98b1..a4ec6cb3010aa7c5a2e7550a119dc13b45780afe 100644 (file)
@@ -9,20 +9,32 @@ class AppFavorites extends Signals.EventEmitter {
 
         // Filter the apps through the user’s parental controls.
         this._parentalControlsManager = ParentalControlsManager.getDefault();
-        this._parentalControlsManager.connect('app-filter-changed', () => {
-            this.reload();
-            this.emit('changed');
-        });
+        this._parentalControlsManager.connect('app-filter-changed',
+            () => this._updateFavorites());
 
         this.FAVORITE_APPS_KEY = 'favorite-apps';
         this._favorites = {};
-        global.settings.connect(`changed::${this.FAVORITE_APPS_KEY}`, this._onFavsChanged.bind(this));
+        global.settings.connect(`changed::${this.FAVORITE_APPS_KEY}`,
+            () => this._updateFavorites());
+
         this.reload();
     }
 
-    _onFavsChanged() {
+    _updateFavorites() {
+        const oldIDs = this._getIds();
         this.reload();
-        this.emit('changed');
+        const newIDs = this._getIds();
+
+        const haveChanged = () => {
+            if (oldIDs.length !== newIDs.length)
+                return true;
+
+            return oldIDs.some(
+                (id, i) => id !== newIDs[i] || !this.isFavorite(id));
+        };
+
+        if (haveChanged())
+            this.emit('changed');
     }
 
     reload() {